<html>
<head><meta charset="utf-8"><title>improving the migration lint · t-compiler/wg-rfc-2229 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/index.html">t-compiler/wg-rfc-2229</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html">improving the migration lint</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244434251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244434251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244434251">(Jun 30 2021 at 14:44)</a>:</h4>
<p>So <span class="user-mention" data-user-id="310399">@Mara</span> was pointing out to me that the quality of the messages you get when migrating could be improved -- basically right now they don't give as much explanation as one might like. I was talking to <span class="user-mention" data-user-id="423254">@Katherine Philip</span> who might be interested in working to help fix that (I thought it'd be good to start helping others get involved in this effort).</p>



<a name="244435254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244435254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244435254">(Jun 30 2021 at 14:50)</a>:</h4>
<blockquote>
<p>messages you get</p>
</blockquote>
<p>important question here though is how often people actually get to see these messages. ideally it'd just be an internal detail to <code>cargo fix --edition</code> when migrating. but i think some users might want to (or have to) look at the messages to understand the migration, or check 'manually' what needs to be migrated.</p>



<a name="244436648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244436648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244436648">(Jun 30 2021 at 14:58)</a>:</h4>
<p>I do think some folks will want to manually migrate (or are forced to e.g. due to macros etc)</p>



<a name="244453623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244453623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Katherine Philip <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244453623">(Jun 30 2021 at 16:49)</a>:</h4>
<p>What does this message look like at the moment?</p>



<a name="244469329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244469329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rocksand <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244469329">(Jun 30 2021 at 18:37)</a>:</h4>
<p><span class="user-mention" data-user-id="423254">@Katherine Philip</span> You can find examples of what they look like here: <a href="https://github.com/rust-lang/rust/blob/master/src/test/ui/closures/2229_closure_analysis/migrations/">https://github.com/rust-lang/rust/blob/master/src/test/ui/closures/2229_closure_analysis/migrations/</a></p>



<a name="244475947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244475947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244475947">(Jun 30 2021 at 19:32)</a>:</h4>
<p><span class="user-mention" data-user-id="423254">@Katherine Philip</span> I will try to file an issue with some specific tests and examples of what we'd like them to say</p>



<a name="244475962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244475962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244475962">(Jun 30 2021 at 19:33)</a>:</h4>
<p>or perhaps <span class="user-mention" data-user-id="281950">@Aman Arora</span> or <span class="user-mention" data-user-id="307184">@rocksand</span> can take a stab at that</p>



<a name="244476020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244476020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244476020">(Jun 30 2021 at 19:33)</a>:</h4>
<p>Here is an <a href="https://github.com/rust-lang/rust/blob/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr#L1-L27">example message</a></p>



<a name="244476124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244476124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244476124">(Jun 30 2021 at 19:34)</a>:</h4>
<p>currently, for example, it says "drop order will change in Rust 2021", but that's a bit terse</p>



<a name="244476182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244476182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244476182">(Jun 30 2021 at 19:34)</a>:</h4>
<p>probably though a good starting step <span class="user-mention" data-user-id="423254">@Katherine Philip</span> is to read <a href="https://hackmd.io/NzREH22HTFq1kefIFG0XSw">this draft blog post</a>  that explains the feature and the migration and why it is necessary</p>



<a name="244476529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244476529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244476529">(Jun 30 2021 at 19:37)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error: changes to closure capture in Rust 2021 will affect when destructors run
  --&gt; $DIR/insignificant_drop_attr_migrations.rs:38:13
   |
LL |       let c = || {
   |   .  .  .  .  ^^ closure is created here
LL | |         let _t = t.0;
   | |.                 --- in Rust 2018, closure captures all of `t`, but in Rust 2021, it only captures `t.0`
   | ...
LL | }
   | - in Rust 2021, `t.1` will be dropped here, instead of being dropped when the closure is dropped
</code></pre></div>



<a name="244476548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244476548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244476548">(Jun 30 2021 at 19:38)</a>:</h4>
<p>something like that, maybe?</p>



<a name="244476635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244476635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244476635">(Jun 30 2021 at 19:38)</a>:</h4>
<p>I think we have all the info we would need to generate that</p>



<a name="244476664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244476664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244476664">(Jun 30 2021 at 19:38)</a>:</h4>
<p>there are other cases too, I imagine they would follow a similar template</p>



<a name="244509181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/244509181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rocksand <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#244509181">(Jul 01 2021 at 01:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/improving.20the.20migration.20lint/near/244475962">said</a>:</p>
<blockquote>
<p>or perhaps <span class="user-mention silent" data-user-id="281950">Aman Arora</span> or <span class="user-mention silent" data-user-id="307184">rocksand</span> can take a stab at that</p>
</blockquote>
<p>I have no preference</p>



<a name="245038657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245038657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rocksand <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245038657">(Jul 06 2021 at 13:31)</a>:</h4>
<p><span class="user-mention" data-user-id="423254">@Katherine Philip</span> Do you want me to take a stab at improving the lint or are you working on it?</p>



<a name="245057018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245057018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Katherine Philip <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245057018">(Jul 06 2021 at 15:40)</a>:</h4>
<p><span class="user-mention" data-user-id="307184">@rocksand</span> I've been away for the holiday weekend, sorry! I haven't really started yet, feel free to take over</p>



<a name="245062325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245062325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rocksand <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245062325">(Jul 06 2021 at 16:13)</a>:</h4>
<p>Ok, I'll take a stab at it then</p>



<a name="245206508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245206508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rocksand <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245206508">(Jul 07 2021 at 16:25)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span>  I wanted to get your opinion on the following lints before I open a PR for review.<br>
Drop migration lint:</p>
<div class="codehilite"><pre><span></span><code>error: changes to closure capture in Rust 2021 will affect drop order
  --&gt; $DIR/significant_drop.rs:163:21
   |
LL |               let c = || {
   |  _____________________^
LL | |
LL | |
LL | |
LL | |                 tuple.0;
   | |                 ------- in Rust 2018, closure captures all of `tuple`, but in Rust 2021, it only captures `tuple.0`
LL | |
LL | |             };
   | |_____________^
...
LL |           }
   |           - in Rust 2018, `tuple` would be dropped here, but in Rust 2021, only `tuple.0` would be dropped here alongside the closure
</code></pre></div>
<p>Auto traits migration lint:</p>
<div class="codehilite"><pre><span></span><code>error: changes to closure capture in Rust 2021 will affect `Send` trait implementation for closure
  --&gt; $DIR/auto_traits.rs:14:19
   |
LL |       thread::spawn(move || unsafe {
   |  ___________________^
LL | |
LL | |
LL | |
LL | |         *fptr.0 = 20;
   | |         ------- in Rust 2018, closure captures all of `fptr`, but in Rust 2021, it only captures `fptr.0`
LL | |
LL | |     });
   | |     ^ in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure would no longer implement `Send` as `fptr.0` does not implement `Send`
   | |_____|
</code></pre></div>



<a name="245228758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245228758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245228758">(Jul 07 2021 at 19:15)</a>:</h4>
<p><span class="user-mention" data-user-id="307184">@rocksand</span> this looks great! My only suggestion would be to change the "overall span" for the lint from tagging the <em>entire</em> closure to just the closure <em>header</em>. I think <span class="user-mention" data-user-id="119031">@Esteban Küber</span> would know if there is any convenient way to do that.</p>



<a name="245228952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245228952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245228952">(Jul 07 2021 at 19:16)</a>:</h4>
<p>There's <code>guess_head_span</code>, but I believe we have now a more principled way of doing that.</p>



<a name="245229003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245229003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245229003">(Jul 07 2021 at 19:17)</a>:</h4>
<p>I would also make the field access be the primary span and the span pointing at the closure secondary</p>



<a name="245243103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245243103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245243103">(Jul 07 2021 at 21:15)</a>:</h4>
<p>The output would then look like</p>
<div class="codehilite"><pre><span></span><code>error: changes to closure capture in Rust 2021 will affect drop order
  --&gt; $DIR/significant_drop.rs:163:21
   |
LL |             let c = || {
   |                     --
LL |
LL |
LL |
LL |                 tuple.0;
   |                 ^^^^^^^ in Rust 2018, closure captures all of `tuple`, but in Rust 2021, it only captures `tuple.0`
...
LL |         }
   |         - in Rust 2018, `tuple` would be dropped here, but in Rust 2021, only `tuple.0` would be dropped here alongside the closure

error: changes to closure capture in Rust 2021 will affect `Send` trait implementation for closure
  --&gt; $DIR/auto_traits.rs:14:19
   |
LL |     thread::spawn(move || unsafe {
   |                   -------------- in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure would no longer implement `Send` as `fptr.0` does not implement `Send`
LL |
LL |
LL |
LL |         *fptr.0 = 20;
   |         ^^^^^^^ in Rust 2018, closure captures all of `fptr`, but in Rust 2021, it only captures `fptr.0`
</code></pre></div>
<p>I have to say that for the case where the closure is more than one line, I personally somewhat prefer the multiline span, but for the case where closure is entirely in a single line, I would likely prefer to point only to the header</p>
<div class="codehilite"><pre><span></span><code>error: changes to closure capture in Rust 2021 will affect `Send` trait implementation for closure
  --&gt; $DIR/auto_traits.rs:14:19
   |
LL |     thread::spawn(move || unsafe { *fptr.0 = 20;
   |                   --------------   ^^^^^^^ in Rust 2018, closure captures all of `fptr`, but in Rust 2021, it only captures `fptr.0`
   |                   |
   |                   in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure would no longer implement `Send` as `fptr.0` does not implement `Send`
</code></pre></div>
<p>although I don't think it is terrible if we don't:</p>
<div class="codehilite"><pre><span></span><code>error: changes to closure capture in Rust 2021 will affect `Send` trait implementation for closure
  --&gt; $DIR/auto_traits.rs:14:19
   |
LL |     thread::spawn(move || unsafe { *fptr.0 = 20; }
   |                   -----------------^^^^^^^--------
   |                   |                |
   |                   |                in Rust 2018, closure captures all of `fptr`, but in Rust 2021, it only captures `fptr.0`
   |                   in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure would no longer implement `Send` as `fptr.0` does not implement `Send`
</code></pre></div>



<a name="245244860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/improving%20the%20migration%20lint/near/245244860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rocksand <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/improving.20the.20migration.20lint.html#245244860">(Jul 07 2021 at 21:29)</a>:</h4>
<p>Ok, I'll try that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>